1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11
12 namespace MilkDairyManagementSystemCSharp
13 {
14 public partial class NewAccount : Form
15 {
16 public NewAccount()
17 {
18 InitializeComponent();
19 }
20
21 private void button1_Click(object sender, EventArgs e)
22 {
23 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True");
24 con.Open();
25 string gen = string.Empty;
26
27 try
28 {
29 string str = "INSERT INTO acnt(name,addr,mobile,center) VALUES('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "'); ";
30
31 SqlCommand cmd = new SqlCommand(str, con);
32 cmd.ExecuteNonQuery();
33
34 string str1 = "select max(Id) from acnt;";
35
36 SqlCommand cmd1 = new SqlCommand(str1, con);
37 SqlDataReader dr = cmd1.ExecuteReader();
38 if (dr.Read())
39 {
40 MessageBox.Show("Inserted FliAccountght Details Information Successfully..");
41 textBox1.Text = "";
42 textBox2.Text = "";
43 textBox4.Text = "";
44 textBox3.Text = "";
45 textBox5.Text = "";
46
47 using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True"))
48 {
49 string str2 = "SELECT * FROM acnt";
50 SqlCommand cmd2 = new SqlCommand(str2, con1);
51 SqlDataAdapter da = new SqlDataAdapter(cmd2);
52 DataTable dt = new DataTable();
53 da.Fill(dt);
54 dataGridView1.DataSource = new BindingSource(dt, null);
55 }
56 }
57 }
58 catch (SqlException excep)
59 {
60 MessageBox.Show(excep.Message);
61 }
62 con.Close();
63 }
64
65 private void NewAccount_Load(object sender, EventArgs e)
66 {
67 // TODO: This line of code loads data into the 'milkdairyDataSet1.acnt' table. You can move, or remove it, as needed.
68 this.acntTableAdapter.Fill(this.milkdairyDataSet1.acnt);
69 using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True"))
70 {
71
72 string str2 = "SELECT * FROM acnt";
73 SqlCommand cmd2 = new SqlCommand(str2, con1);
74 SqlDataAdapter da = new SqlDataAdapter(cmd2);
75 DataTable dt = new DataTable();
76 da.Fill(dt);
77
78 dataGridView1.DataSource = new BindingSource(dt, null);
79 }
80 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True");
81 con.Open();
82 string str1 = "select max(id) from acnt;";
83
84 SqlCommand cmd1 = new SqlCommand(str1, con);
85 SqlDataReader dr = cmd1.ExecuteReader();
86 if (dr.Read())
87 {
88 string val = dr[0].ToString();
89 if (val == "")
90 {
91 textBox1.Text = "1";
92 }
93 else
94 {
95 int a;
96 a = Convert.ToInt32(dr[0].ToString());
97 a = a + 1;
98 textBox1.Text = a.ToString();
99 }
100 }
101 con.Close();
102 }
103
104 private void button2_Click(object sender, EventArgs e)
105 {
106 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True");
107 con.Open();
108 if (textBox1.Text != "")
109 {
110 try
111 {
112 string getCust = "select name,addr,mobile,center from acnt where id=" + Convert.ToInt32(textBox1.Text) + " ;";
113
114 SqlCommand cmd = new SqlCommand(getCust, con);
115 SqlDataReader dr;
116 dr = cmd.ExecuteReader();
117 if (dr.Read())
118 {
119 textBox2.Text = dr.GetValue(0).ToString();
120 textBox3.Text = dr.GetValue(1).ToString();
121 textBox4.Text = dr.GetValue(2).ToString();
122 textBox5.Text = dr.GetValue(3).ToString();
123
124
125 }
126 else
127 {
128 MessageBox.Show(" Sorry, This ID, " + textBox1.Text + " Account Details Record is not Available. ");
129 textBox1.Text = "";
130 }
131 }
132 catch (SqlException excep)
133 {
134 MessageBox.Show(excep.Message);
135 }
136 con.Close();
137 }
138 }
139
140 private void button4_Click(object sender, EventArgs e)
141 {
142 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True");
143 con.Open();
144 try
145 {
146 string str = " Update acnt set name='" + textBox2.Text + "',addr='" + textBox3.Text + "',mobile='" + textBox4.Text + "',center='" + textBox5.Text + "' where id='" + textBox1.Text + "'";
147
148 SqlCommand cmd = new SqlCommand(str, con);
149 cmd.ExecuteNonQuery();
150
151 string str1 = "select max(id) from acnt;";
152
153 SqlCommand cmd1 = new SqlCommand(str1, con);
154 SqlDataReader dr = cmd1.ExecuteReader();
155 if (dr.Read())
156 {
157 MessageBox.Show("" + textBox2.Text + "'s Details is Updated Successfully.. ", "Important Message");
158 textBox2.Text = "";
159 textBox4.Text = "";
160 textBox3.Text = "";
161 textBox5.Text = "";
162 textBox1.Text = "";
163
164 using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True"))
165 {
166 string str2 = "SELECT * FROM acnt";
167 SqlCommand cmd2 = new SqlCommand(str2, con1);
168 SqlDataAdapter da = new SqlDataAdapter(cmd2);
169 DataTable dt = new DataTable();
170 da.Fill(dt);
171 dataGridView1.DataSource = new BindingSource(dt, null);
172 }
173 }
174 }
175 catch (SqlException excep)
176 {
177 MessageBox.Show(excep.Message);
178 }
179 con.Close();
180 }
181
182 private void button3_Click(object sender, EventArgs e)
183 {
184 textBox2.Text = "";
185 textBox4.Text = "";
186 textBox3.Text = "";
187 textBox5.Text = "";
188 textBox1.Text = "";
189 }
190 }
191 }